package com.ndpmedia.fb.pmd.configration.service.impl;

import com.ndpmedia.fb.pmd.configration.db.ConfigRepository;
import com.ndpmedia.fb.pmd.configration.db.PropertiesRepository;
import com.ndpmedia.fb.pmd.configration.model.po.ConfigPo;
import com.ndpmedia.fb.pmd.configration.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2014/10/12.
 */
@Service
public class ConfigServiceImpl implements ConfigService {
    @Autowired
    private ConfigRepository configRepository;
    @Autowired
    private PropertiesRepository propertiesRepository;

    @Override
    public List list(String appid) {
        return configRepository.findAll(appid);
    }

    @Override
    public ConfigPo add(String appid, String name) {
        return configRepository.save(appid, name);
    }

    @Override
    public boolean push(String appid, String configid) {
/*

        com.fourinone.ParkLocal parkLocal = this.getParkLocal();

        ConfigPo configPo = configRepository.findById(configid);
        String configName = configPo.getName();
        String configFlagName = configName + "flag";

        ObjectBean bean = parkLocal.get(appid, configName);
        ObjectBean beanFlag = parkLocal.get(appid, configFlagName);

        ArrayList preps = (ArrayList) propertiesRepository.findAll(appid, configid);

        if (bean == null) {
            parkLocal.create(appid, configName, preps);
        } else {
            parkLocal.update(appid, configName, preps);
        }
        if (beanFlag == null) {
            parkLocal.create(appid, configFlagName, configFlagName + System.currentTimeMillis());
        } else {
            parkLocal.update(appid, configFlagName, configFlagName + System.currentTimeMillis());
        }
*/


        return true;
    }


    @Override
    public boolean delete(String configid) {
        return configRepository.delete(configid);
    }

    @Override
    public boolean update(String configid, String name) {
        return configRepository.update(configid, name);
    }

    @Override
    public boolean status(String configid, String status) {
        return configRepository.updateStatus(configid, status);
    }

  /*  private com.fourinone.ParkLocal getParkLocal() {
        return client.getParkLocal();
    }*/
}
